<template>
  <div class="container-content">
    <el-table
      v-loading="loading"
      ref="materialTable"
      :data="tableData"
      stripe
      border
      style="width: 100%"
      @selection-change="getSelectVal"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
      ></el-table-column>
      <el-table-column
        type="index"
        label="序号"
        align="center"
      ></el-table-column>
      <el-table-column prop="meteringUnitCode" label="编码"></el-table-column>
      <el-table-column prop="meteringUnitName" label="名称"></el-table-column>
      <el-table-column
        prop="meteringUnitGroupId"
        label="所属组别"
      ></el-table-column>
      <el-table-column
        prop="exchangeNumerator"
        label="换算分字"
      ></el-table-column>
      <el-table-column
        prop="exchangeDenominator"
        label="换算分母"
      ></el-table-column>
      <el-table-column prop="isBase" label="是否基准计量单位">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isBase" type="success">是</el-tag>
          <el-tag v-else-if="!scope.row.isBase" type="danger">否</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="meteringUnitDescribe"
        label="描述"
      ></el-table-column>
    </el-table>
    <el-pagination
      class="pagination mt10"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      background
    >
    </el-pagination>
  </div>
</template>
<script>
import { getUnitData } from "@/api/base/data";
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1, //当前页
      pageSize: 10, //每页条数
      total: 0,
      loading: false,
    };
  },
  methods: {
    //分页器size
    handleSizeChange(val) {
      this.pageSize = val;
      this.getDataList();
    },
    //分页器当前页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getDataList();
    },
    getSelectVal(val) {
      // if (val.length) {
      this.$emit("update:visible", false);
      this.$emit("getSelectVal", val);
      // }
    },
    getDataList() {
      this.loading = true;
      getUnitData({
        page: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        this.loading = false;
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
  },
  mounted() {
    this.getDataList();
  },
};
</script>
<style lang="scss" scoped></style>
